//
//  HTLoginBoolView.swift
//  weibo
//
//  Created by JonsonLiu on 16/4/17.
//  Copyright © 2016年 liujonson. All rights reserved.
//

import UIKit

import SnapKit
@objc protocol  HTLoginBoolViewDelegate : NSObjectProtocol{

    func loginButtonClick()
    
    func regsterButtonClick()
    
    optional func home()
}


class HTLoginBoolView: UIView {

    
    // MARK: 定义代理属性
    weak var delegate : HTLoginBoolViewDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setControllerImage(imageName:String? , message:String?){
        
        if let img = imageName , mes = message{
        
        iconView.image = UIImage(named: img)
        messageLable.text = mes
        }else{
        
            startAmin()
        }
    }
    
    private func startAmin(){
    
        crileView.hidden = false
        
        let anmi = CABasicAnimation(keyPath: "transform.rotation")
        
        anmi.toValue = 2 * M_PI
        anmi.repeatCount = MAXFLOAT
        anmi.duration = 20
        anmi.removedOnCompletion = false
        
        crileView.layer.addAnimation(anmi, forKey: nil)
        
    }
    
    
    private func setupUI(){
        
        
    
        backgroundColor = UIColor(white: 237/255.0, alpha: 1)
        
        addSubview(crileView)
        addSubview(maskIconView)
        addSubview(iconView)
        addSubview(messageLable)
        addSubview(loginButton)
        addSubview(registerButton)
        
        
        iconView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        
        crileView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(iconView)
        }
        
        messageLable.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView)
            make.top.equalTo(crileView.snp_bottom).offset(15)
        }
        
        registerButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(messageLable)
            make.top.equalTo(self.messageLable.snp_bottom)
            make.width.equalTo(100)
        }
        
        loginButton.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(messageLable)
            make.top.equalTo(registerButton)
            make.width.equalTo(100)
        }
        
        maskIconView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(crileView)
        }
        
    }
    
    
    func loginButtonClick(){
    
        delegate?.loginButtonClick()
    }
    func regsterButtonClick(){
    
        delegate?.regsterButtonClick()
    }
    
    
    
    private lazy var iconView : UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var crileView : UIImageView = {
    
        let image = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
        
        image.hidden = true
        
        return image
    
    }()
    
    private lazy var messageLable : UILabel = {
    
        let label = UILabel()
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(18.0)
        
        label.text = "这里就不封装了,太麻烦了,.........................................."
        label.textAlignment = .Center
        
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = 260
        return label
        
    }()
    
    private lazy var loginButton : UIButton = {
    
        let logButton = UIButton()
        
        logButton.setTitle("注册", forState: .Normal)
        logButton.addTarget(self, action: "regsterButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        logButton.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        logButton.setBackgroundImage(UIImage(named:"common_button_white"), forState: .Normal)
        logButton.titleLabel?.font = UIFont.systemFontOfSize(14.0)
        return logButton
    }()
    
    private lazy var registerButton: UIButton = {
        
        let resButton = UIButton()
        
        resButton.setTitle("登陆", forState: .Normal)
        resButton.addTarget(self, action: "loginButtonClick", forControlEvents: .TouchUpInside)
        resButton.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        resButton.setBackgroundImage(UIImage(named:"common_button_white"), forState: .Normal)
        resButton.titleLabel?.font = UIFont.systemFontOfSize(14.0)
        return resButton
        
    }()
    
     private lazy var maskIconView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
}
